﻿using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using NHibernate;
using Common;
using Educational.Model.Entity;
using Educational.Model.EntityManager;

namespace Educational.Business
{
    public class SchoolRoleAdmin
    {
        #region AddSchoolRole添加权限
        /// <summary>
        /// 添加权限 
        /// </summary>
        /// <param name="roleName"></param>
        /// <param name="categoryName"></param>
        public static void AddSchoolRole(string roleName,string categoryName)
        {
            ISession session = null;
            ITransaction trans = null;
            try
            {
                session = NHibernateHelper.OpenSession();
                trans = session.BeginTransaction();
                SchoolRole schoolRole = new SchoolRole();
                schoolRole.roleName = roleName;
                schoolRole.schoolRoleCategory = SchoolRoleCategoryManager.Get1(session, categoryName);
                if (schoolRole.schoolRoleCategory == null)
                    throw new Exception("不存在这个权限分类，请先添加权限分类！");
                SchoolRoleManager.Add(session, schoolRole);
                trans.Commit();
            }
            catch
            {
                if (trans != null)
                    trans.Rollback();
                throw;
            }
            finally
            {
                if (session != null)
                    session.Close();
            }
        }
        #endregion
    }
}
